package com.hundsun.cprs.yyt.service.common.service.impl;

import com.hundsun.cprs.plate.RemotePlateService;
import com.hundsun.cprs.plate.response.PlateResponse;
import com.hundsun.cprs.yyt.service.common.dto.AreaInfo;
import com.hundsun.cprs.yyt.service.common.service.RemoteCommonService;
import com.hundsun.cprs.yyt.util.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class RemoteCommonServiceImpl implements RemoteCommonService {

    @Autowired(required = false)
    private RemotePlateService remotePlateService;

    @Override
    public List<AreaInfo> getProvinces() {
        List<AreaInfo> areaInfos = new ArrayList<>();
        PlateResponse response = remotePlateService.getProvinces();
        if (response != null && CollectionUtils.isNotEmpty(response.getPlateVoList())){
            areaInfos = BeanUtils.batchTransform(AreaInfo.class,response.getPlateVoList());
        }
        return areaInfos;
    }

    @Override
    public List<AreaInfo> getCitysByProvince(Integer provinceId) {
        List<AreaInfo> areaInfos = new ArrayList<>();
        PlateResponse response = remotePlateService.getCitysByProvince(provinceId);
        if (response != null && CollectionUtils.isNotEmpty(response.getPlateVoList())){
            areaInfos = BeanUtils.batchTransform(AreaInfo.class,response.getPlateVoList());
        }
        return areaInfos;
    }

    @Override
    public List<AreaInfo> getAreasByCity(Integer cityId) {
        List<AreaInfo> areaInfos = new ArrayList<>();
        PlateResponse response = remotePlateService.getAreasByCity(cityId);
        if (response != null && CollectionUtils.isNotEmpty(response.getPlateVoList())){
            areaInfos = BeanUtils.batchTransform(AreaInfo.class,response.getPlateVoList());
        }
        return areaInfos;
    }
}
